package filter

import (
	"adam2/internal/properties"
	"anubis-framework/pkg/io"
	"gorm.io/gorm"
)

// 过滤器：删除总市值不满足要求的股票
type TotalMarketValueBottomLimitFilter struct {
	db *gorm.DB
}

// 初始化
func (t *TotalMarketValueBottomLimitFilter) Init(db *gorm.DB) {
	t.db = db
}

// 执行
func (t *TotalMarketValueBottomLimitFilter) DoFilter(transactionDate string) {
	io.Infoln("过滤器：删除总市值不满足要求的股票，交易日期[%s]", transactionDate)

	var marketValueMainBoardBottomLimit float64 = properties.QuantProperties_.MarketValueMainBoardBottomLimit
	var marketValueCyBBoardBottomLimit float64 = properties.QuantProperties_.MarketValueCyBBoardBottomLimit

	// 过滤器：删除总市值不满足要求的股票
	t.db.Exec("delete quant_stock_filter t2 where t2.stock_code in("+
		"select distinct t.code_ from stock_transaction_data_all t where t.date_ = to_date(?, 'yyyy-mm-dd') "+
		"and t2.stock_code=t.code_ and t.total_market_value/100000000<? "+
		"and (t.code_ like '60%' or t.code_ like '00%'))",
		transactionDate, marketValueMainBoardBottomLimit)
	t.db.Exec("delete quant_stock_filter t2 where t2.stock_code in("+
		"select distinct t.code_ from stock_transaction_data_all t where t.date_ = to_date(?, 'yyyy-mm-dd') "+
		"and t2.stock_code=t.code_ and t.total_market_value/100000000<? "+
		"and t.code_ like '30%' or t.code_ like '68%')",
		transactionDate, marketValueCyBBoardBottomLimit)
}
